import request from '@/utils/request'

// 查询资产列表
export function listAsset(query) {
  return request({
    url: '/system/asset/list',
    method: 'get',
    params: query
  })
}

// 查询资产列表（DTO格式，用于前端下拉选择）
export function listAssetDTO(query) {
  return request({
    url: '/system/asset/list-dto',
    method: 'get',
    params: query
  })
}

// 查询资产详细
export function getAsset(assetNo) {
  return request({
    url: '/system/asset/' + assetNo,
    method: 'get'
  })
}

// 新增资产
export function addAsset(data) {
  return request({
    url: '/system/asset',
    method: 'post',
    data: data
  })
}

// 修改资产
export function updateAsset(data) {
  return request({
    url: '/system/asset',
    method: 'put',
    data: data
  })
}

// 删除资产
export function delAsset(assetNo) {
  return request({
    url: '/system/asset/' + assetNo,
    method: 'delete'
  })
}

// 导出资产
export function exportAsset(query) {
  return request({
    url: '/system/asset/export',
    method: 'get',
    params: query
  })
}

// 更新资产状态
export function updateAssetStatus(assetNo, statusCode) {
  return request({
    url: '/system/asset/status',
    method: 'put',
    data: {
      assetNo: assetNo,
      statusCode: statusCode
    }
  })
}

// 批量更新资产状态
export function batchUpdateAssetStatus(assetNos, statusCode) {
  return request({
    url: '/system/asset/batchStatus',
    method: 'put',
    data: {
      assetNos: assetNos,
      statusCode: statusCode
    }
  })
}

// 获取资产统计信息
export function getAssetStatistics() {
  return request({
    url: '/system/asset/statistics',
    method: 'get'
  })
}

// 获取资产维修历史
export function getAssetRepairHistory(query) {
  return request({
    url: '/system/record/asset/complete/' + query.assetNo,
    method: 'get',
    params: {
      startDate: query.startDate,
      endDate: query.endDate,
      pageNum: query.pageNum,
      pageSize: query.pageSize
    }
  })
}

// 上传资产图片
export function uploadAssetImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/system/asset/uploadImage',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除资产图片
export function deleteAssetImage(assetNo, imageUrl) {
  return request({
    url: '/system/asset/deleteImage',
    method: 'delete',
    params: {
      assetNo: assetNo,
      imageUrl: imageUrl
    }
  })
}